/*---------------------------------------------------------------------------*\
|* This file is part of the koala project with MIT License.                  *|
|* Copyright (c) James <zhuguangxiang@gmail.com>                             *|
\*--------------------------------------------------------------------------**/

#ifndef _KOALA_VM_OPCODE_H_
#define _KOALA_VM_OPCODE_H_

#ifdef __cplusplus
extern "C" {
#endif

/* clang-format off */

typedef enum _KlOpCode {
    OP_HALT, /* halt VM */
    OP_MOVE, /* R[A] = R[B] */
    OP_MOVE_TOP, /* R[A] = R[top--] */
    OP_CONST_IMM8, /* R[A] = imm_8 */
    OP_CONST_IMM16, /* R[A] = imm_16 */
    OP_CONST_LOAD, /* R[A] = K[index_8] */
    OP_CONST_LOAD_W, /* R[A] = K[index_16] */

    OP_I32_ADD,
    OP_I32_SUB,
    OP_I32_EQ,
    OP_I32_NE,
    OP_I32_GT,
    OP_I32_GE,
    OP_I32_LT,
    OP_I32_LE,
    OP_JMP,

    OP_GET_FIELD, /* R[A] = OBJ[idx] */
    OP_SET_FIELD, /* A, idx, B, R[A][idx] = R[B] */
    OP_SET_FIELD_I8, /* A, idx, imm_i8 */
    OP_LOAD_GLOBAL, /* R[A] = K[idx1][idx2] */
    OP_STORE_GLOBAL, /* K[idx1][idx2] = R[A] */
} KlOpCode;

/* clang-format on */

#ifdef __cplusplus
}
#endif

#endif /* _KOALA_VM_OPCODE_H_ */
